<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

    <head>
		<title>注册</title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        <script type="application/x-javascript">
        addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); }
	</script>

	<!-- //Meta-Tags -->

	<!-- Style --> <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
	<body>

	<h1>注册</h1>

	<div class="container w3layouts agileits">


			<div  class="register w3layouts agileits">
			<h2>注 册</h2>
			<form  action="../controller/register_add.jsp" method="post" onsubmit="return checkAll()" name="name"  	>
				<div><span  id="demo1" style="color:red;"></span></div>
				<input type="text" Name="userName" id="userName" placeholder="用户名" required="" autocomplete="off">
				<div><span  id="demo2" style="color:red;"></span></div>
				<input type="text" Name="userPhone" id="userPhone" placeholder="手机号码" required="" onclick="clicks()" autocomplete="off">
				<div><span  id="demo3" style="color:red;"></span></div>
				<input type="text" Name="userEmail" placeholder="邮箱" id="userEmail" required="" onclick="clicks2()" autocomplete="off">
				<div><span  id="demo4" style="color:red;"></span></div>
				<input type="password" Name="userPsw" placeholder="密码" id="userPsw" required="" onclick="clicks3()" autocomplete="off">
				<div><span  id="demo5" style="color:red;"></span></div>
				<input type="password" Name="reuserPsw" placeholder="确认密码" id="reuserPsw" required="" onclick="clicks4()" autocomplete="off">
				<div><span  id="demo6" style="color:red;"></span></div>

			<div style="text-align:center;" class="send-button w3layouts agileits">
			
			<%
				       Integer countn = (Integer)session.getAttribute("countn");
				       if( countn==null || countn==0){
					%>
			
					<%
					} 
					else if(countn==1){
					%>
					<div style="position:absolute;left:750px;top:650px;width:200px;height:50px;background:white;">
					<div style="color:red;font-size:13px;padding:15px 20px;">注册成功正在为你跳转...</div>
					</div>
					<% session.removeAttribute("countn");
					response.setHeader("refresh","1;login.jsp"); %>
					<%
					}
					else{
					%>
					<p style="color:red;font-size:12px;">已有账号，注册 失败</p>
					<%
					}
					%>
					<input type="submit"  onclick="clicks5()" value="注册" autocomplete="off" formnovalidate>
			</div>
			</form>
				<div style="text-align:right;">
					<a  href="login.jsp">立即登录></a>
					
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<div class="clear"></div>

	</div>
	<script src="js/jquery-1.11.1.min.js"></script>
	<script src="js/jquery.backstretch.min.js"></script>
	<script>
        function clicks(){
            var x=document.getElementById("userName").value;
            var y = document.getElementById('demo1');
            if(x == '' || x == undefined || x == null){
                y.innerHTML = "昵称不能为空";
                return false;
            }
            else if(x.length<2){
                y.innerHTML = "昵称至少2个字符 ";
                return false;
            }
            else{
                y.innerHTML = "  ";
                return true;
            }
        }
        function clicks2(){
            var x=document.getElementById("userPhone").value;
            var y = document.getElementById('demo2');
            if(x == '' || x == undefined || x == null){
                y.innerHTML = "手机号不能为空";
                return false;
            }
            else if(x.length!=11){
                y.innerHTML = "手机号格式错误 ";
                return false;
            }
            else{
                y.innerHTML = "  ";
                return true;
            }
        }
        function clicks3(){
            var email_reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            var x=document.getElementById("userEmail").value;
            var y = document.getElementById('demo3');
            if(x == '' || x == undefined || x == null){
                y.innerHTML = "电子邮箱不能为空！";
                return false;
            }
            else if( email_reg.test(x)){
                y.innerHTML = "  ";
                return true;
            }
            else{
                y.innerHTML = " 电子邮箱格式错误！ ";
                return false;
            }
        }
        function clicks4(){
            var x=document.getElementById("userPsw").value;
            var y = document.getElementById('demo4');
            if(x == '' || x == undefined || x == null){
                y.innerHTML = "密码不能为空";
                return false;
            }
            else if(x.length<6){
                y.innerHTML = "密码至少6个字符 ";
                return false;
            }
            else{
                y.innerHTML = "  ";
                return true;
            }
        }
        function clicks5(){
            var x=document.getElementById("userPsw").value;
            var z=document.getElementById("reuserPsw").value;
            var y = document.getElementById('demo5');
            if(z == '' || x == undefined || x == null){
                y.innerHTML = "确认密码不能为空";
                return false;
            }
            else if(x!=z){
                y.innerHTML = "两次密码不一致 ";
                return false;
            }
            else{

                return true;
            }
        }
        function checkAll(){
            var a = clicks();
            var b = clicks2();
            var c = clicks3();
            var d = clicks4();
            var e = clicks5();
            var y = document.getElementById('demo6');
            if(a&&b&&c&&d&&e){
                return true;
            }
            else{
                y.innerHTML = "注册失败 ！";
                return false;
            }

        }

	</script>
    </body>
</html>